package com.lintesis.lintesisview.common.constraints;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

public class URLConstraint implements Constraint {

	@Override
	public void validate(Component comp, Object value)
			throws WrongValueException {
		String pattern = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
		String stringValue=(String)value;
		if (value != null && stringValue.length()>0 && !stringValue.matches(pattern)) {
			
			throw new WrongValueException(comp,
					"Enter a valid URL");
		}
	}

}
